package com.bq.gametrade.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.bean.InterconnectedDetails;

import java.util.ArrayList;

/**
 * @author Feel on 2016/11/30 17:33
 */

public class InterconnectedDetailsListAdapter extends BaseAdapter {

    private ArrayList<InterconnectedDetails> list;
    private Context context;

    public InterconnectedDetailsListAdapter(Context context, ArrayList<InterconnectedDetails> items) {
        this.context = context;
        this.list = items;
    }

    public void setData(ArrayList<InterconnectedDetails> items){
        this.list = items;
        }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_interconnectedetails_item, null);
            viewHolder.tvOperaDate = (TextView) convertView.findViewById(R.id.tv_operationDate);
            viewHolder.tvGamesName = (TextView) convertView.findViewById(R.id.tv_gameName);
            viewHolder.tvGameAccount = (TextView) convertView.findViewById(R.id.tv_gameAccount);
            viewHolder.tvIntoFishStamps = (TextView) convertView.findViewById(R.id.tv_intoFishStamps);
            viewHolder.tvOutFishStamps = (TextView) convertView.findViewById(R.id.tv_outFishStamps);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        InterconnectedDetails details = list.get(position);
        viewHolder.tvOperaDate.setText(details.ctime);
        viewHolder.tvGamesName.setText(details.serverName);
        viewHolder.tvGameAccount.setText(details.account);
        //0:转入，1：转出
        if(details.tran_type.equals("0")){
            viewHolder.tvIntoFishStamps.setText(details.ticket);
            viewHolder.tvIntoFishStamps.setTextColor(context.getResources().getColor(R.color.red));
            viewHolder.tvOutFishStamps.setText("/");
            viewHolder.tvOutFishStamps.setTextColor(context.getResources().getColor(R.color.text));
        }else if(details.tran_type.equals("1")){
            viewHolder.tvOutFishStamps.setText(details.ticket);
            viewHolder.tvOutFishStamps.setTextColor(context.getResources().getColor(R.color.green_28A71C));
            viewHolder.tvIntoFishStamps.setText("/");
            viewHolder.tvIntoFishStamps.setTextColor(context.getResources().getColor(R.color.text));

        }



        return convertView;
    }

    class ViewHolder {
        TextView tvOperaDate;
        TextView tvGamesName;
        TextView tvGameAccount;
        TextView tvIntoFishStamps;
        TextView tvOutFishStamps;
    }
}
